package com.guli.mall.wms.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.guli.mall.wms.entity.vo.PurchaseDetailWithKeyVo;
import com.guli.mall.wms.entity.vo.PurchaseDetailWithSkuNameVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.guli.mall.wms.entity.PurchaseDetailEntity;
import com.guli.mall.wms.service.PurchaseDetailService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;


/**
 * @author 罗俊华
 * @email 1007052116@qq.com
 * @date 2020-09-29 21:37:28
 */
@RestController
@RequestMapping("wms/purchasedetail")
public class PurchaseDetailController {

    @Autowired
    private PurchaseDetailService purchaseDetailService;


    @PostMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取purchaseDetail分页列表")
    /*@ApiImplicitParam(name = "params" , paramType = "body",examples = @Example({
            @ExampleProperty(value = "{'user':'id'}", mediaType = "application/json")
    }))*/
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size,
                  @RequestBody PurchaseDetailWithKeyVo purchaseDetailWithKeyVo) {

        PageUtils<PurchaseDetailWithSkuNameVo> page = purchaseDetailService.queryPage(currentPage, size, purchaseDetailWithKeyVo);

        return R.ok().put("page", page);
    }

    @GetMapping("/info/{id}")
    @ApiOperation("根据id获取PurchaseDetail")
    public R info(@PathVariable("id") Long id) {
        PurchaseDetailEntity purchaseDetail = purchaseDetailService.getById(id);

        return R.ok().put("purchaseDetail", purchaseDetail);
    }

    @PostMapping("/save")
    @ApiOperation("插入PurchaseDetail")
    public R save(@RequestBody PurchaseDetailEntity purchaseDetail) {
        purchaseDetailService.save(purchaseDetail);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据id更新PurchaseDetail")
    public R update(@RequestBody PurchaseDetailEntity purchaseDetail) {
        purchaseDetailService.updateById(purchaseDetail);

        return R.ok();
    }

    @PostMapping("/updateBatch")
    @ApiOperation("批量更新")
    public R updateBatch(@RequestBody List<PurchaseDetailEntity> purchaseDetailList) {
        //TODO 更新之前要检查采购需求的状态,等下弃用这个方法，不用它来进行更新订单状态，因为要验证状态，改前端
        purchaseDetailService.updateBatchById(purchaseDetailList);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据id批量删除PurchaseDetail")
    public R delete(@RequestBody Long[] ids) {
        purchaseDetailService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
